package com.yuqiaotech.zcj.filter;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.yuqiaotech.zcj.auth.model.User;

public class MyInterceptor implements Interceptor {
	User user;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		System.out.println("--------过滤器初始化le --------");

	}

	public String intercept(ActionInvocation invocation) throws Exception {
		String result = null;
		Map session = invocation.getInvocationContext().getSession();
		int test=session.size();
		Set entry=session.entrySet();
		Iterator it=entry.iterator();
		while(it.hasNext()){
			Map.Entry en=(Entry) it.next();
		}
		if (test>0) {
			System.out.println("拦截器：合法用户登录---");
			return invocation.invoke();
		} else {
			System.out.println("拦截器：用户未登录---");
			return "login";
		}
	}
}
